package filmring

class DirectorController {

    def index = {

    }

    def show = {
       Director director = Director.get(params.id as Long)
        FRUser user =null
        if(session.user!=null){
            user = FRUser.get(session.user)
        }
        List<Movie> movies = new ArrayList<Movie>()
        for(Movie movie : director.movies){
            movies.add(movie)
        }
        List<Rating> ratings = new ArrayList<Rating>()
        for(Movie movie: movies){
            Rating rating = Rating.findByUserAndMovie(user, movie)
            if(rating==null){
                rating=new Rating(user:user, movie:movie, rating:0)
            }
            ratings.add(rating)
        }
        render(view: "show", model:[director:director, user:user, ratings:ratings, movies:movies])
    }
}
